﻿namespace Nancy.Demo.Hosting.Aspnet
{
    using Nancy.ErrorHandling;

    public class CustomStatusCodeHandler : IStatusCodeHandler
    {
        /// <summary>
        /// Check if the error handler can handle errors of the provided status code.
        /// </summary>
        /// <param name="statusCode">Status code</param>
        /// <param name="context">The <see cref="NancyContext"/> instance of the current request.</param>
        /// <returns>True if handled, false otherwise</returns>
        public bool HandlesStatusCode(HttpStatusCode statusCode, NancyContext context)
        {
            return statusCode == HttpStatusCode.ImATeapot;
        }

        /// <summary>
        /// Handle the error code
        /// </summary>
        /// <param name="statusCode">Status code</param>
        /// <param name="context">Current context</param>
        public void Handle(HttpStatusCode statusCode, NancyContext context)
        {
            context.Response = "Response generated by a custom error handler";
        }
    }
}